home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / C⁄C++ OS8 / AMReminder / Add.cp next >
Encoding:
Text File  |  1998-10-17  |  3.7 KB  |  158 lines  |  [TEXT/CWIE]

  1. // Add.cp -- Modal dialog
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <TextEdit.h>
  11. #include <Appearance.h>
  12.  
  13. #include "ResourceDefs.h"
  14. #include "Miscellany.h"
  15. #include "ControlUtils.h"
  16.  
  17. #include "Add.h"
  18.  
  19. #define kOKButton        1
  20. #define kCancelButton        2
  21. #define kLogoImage        3
  22. #define kAddReminderForLabel        4
  23. #define kDateLabel        5
  24. #define kDate2Field        6
  25. #define kTimeLabel        7
  26. #define kTime2Field        8
  27. #define kMessageLabel        9
  28. #define kMessage2Field        10
  29. #define kWhenRemindingLabel        11
  30. #define kDisplayIconCheck        12
  31. #define kDisplayAlertCheck        13
  32. #define kPlaySoundCheck        14
  33. #define kSoundPopupPopup        15
  34.  
  35.  
  36. //----------
  37. // static
  38. Boolean        CAdd::GetAdd (
  39.     DReminder*        ioData)
  40. {
  41.     Boolean            result = false;
  42.     CAdd*        dialog = new CAdd;
  43.  
  44.     result = dialog->RunModal (DLOG_Add, ioData);
  45.  
  46.     delete dialog;
  47.  
  48.     return result;
  49. }
  50.  
  51. //----------
  52. CAdd::CAdd ()
  53. {
  54.     mData = nil;
  55. }
  56.  
  57. //----------
  58. CAdd::~CAdd ()
  59. {
  60. }
  61.  
  62. //----------
  63. void    CAdd::FinishMake ()
  64. {
  65.     mOKHandle = GetControlItem (kOKButton);
  66.     SetDefaultState (mOKHandle, true);
  67.     ::SetDialogDefaultItem (mDialog, kOKButton);
  68.     mCancelHandle = GetControlItem (kCancelButton);
  69.     ::SetDialogCancelItem (mDialog, kCancelButton);
  70.     mDate2Handle = GetControlItem (kDate2Field);
  71.     mTime2Handle = GetControlItem (kTime2Field);
  72.     mMessage2Handle = GetControlItem (kMessage2Field);
  73.     mDisplayIconHandle = GetControlItem (kDisplayIconCheck);
  74.     mDisplayAlertHandle = GetControlItem (kDisplayAlertCheck);
  75.     mPlaySoundHandle = GetControlItem (kPlaySoundCheck);
  76.     mSoundPopupHandle = GetControlItem (kSoundPopupPopup);
  77. }
  78.  
  79. //----------
  80. void    CAdd::ConnectToData (
  81.     AMSignaler*        inData)
  82. {
  83.     AMDialog::ConnectToData (inData);
  84.     mData = (DReminder*) inData;
  85.  
  86.     SetClockDateTime (mDate2Handle, mData->GetYearMonthDay ());
  87.     SetClockDateTime (mTime2Handle, mData->GetHourMinute ());
  88.     SetControlText (mMessage2Handle, mData->GetMessage ());
  89.     SetControlValue (mDisplayIconHandle, mData->GetShowIcon ());
  90.     SetControlValue (mDisplayAlertHandle, mData->GetShowAlert ());
  91.     SetControlValue (mPlaySoundHandle, mData->GetPlaySound ());
  92.     SetControlValue (mSoundPopupHandle, mData->GetSoundIndex ());
  93. }
  94.  
  95. //----------
  96. void    CAdd::DataChanged (
  97.     long        inDataID)
  98. {
  99.     if (inDataID == idYearMonthDay) {
  100.         SetClockDateTime (mDate2Handle, mData->GetYearMonthDay ());
  101.     }
  102.     if (inDataID == idHourMinute) {
  103.         SetClockDateTime (mTime2Handle, mData->GetHourMinute ());
  104.     }
  105.     if (inDataID == idMessage) {
  106.         SetControlText (mMessage2Handle, mData->GetMessage ());
  107.     }
  108.     if (inDataID == idShowIcon) {
  109.         SetControlValue (mDisplayIconHandle, mData->GetShowIcon ());
  110.     }
  111.     if (inDataID == idShowAlert) {
  112.         SetControlValue (mDisplayAlertHandle, mData->GetShowAlert ());
  113.     }
  114.     if (inDataID == idPlaySound) {
  115.         SetControlValue (mPlaySoundHandle, mData->GetPlaySound ());
  116.     }
  117.     if (inDataID == idSoundIndex) {
  118.         SetControlValue (mSoundPopupHandle, mData->GetSoundIndex ());
  119.     }
  120. }
  121.  
  122.  
  123. //----------
  124. void    CAdd::DoItem (
  125.     SInt16        inItemHit)
  126. {
  127.     switch (inItemHit) {
  128.     case kOKButton:
  129.             SetResult (true);
  130.         break;
  131.     case kCancelButton:
  132.             SetResult (false);
  133.         break;
  134.     case kDate2Field:
  135.             mData->SetYearMonthDay (GetClockDateTime (mDate2Handle));
  136.         break;
  137.     case kTime2Field:
  138.             mData->SetHourMinute (GetClockDateTime (mTime2Handle));
  139.         break;
  140.     case kMessage2Field:
  141.             mData->SetMessage (GetEditTextChars (mMessage2Handle));
  142.         break;
  143.     case kDisplayIconCheck:
  144.             mData->SetShowIcon (ToggleCheckbox (mDisplayIconHandle));
  145.         break;
  146.     case kDisplayAlertCheck:
  147.             mData->SetShowAlert (ToggleCheckbox (mDisplayAlertHandle));
  148.         break;
  149.     case kPlaySoundCheck:
  150.             mData->SetPlaySound (ToggleCheckbox (mPlaySoundHandle));
  151.         break;
  152.     case kSoundPopupPopup:
  153.             mData->SetSoundIndex (GetControlValue (mSoundPopupHandle));
  154.         break;
  155.  
  156.     } // switch
  157. }
  158.